import 'package:flutter/material.dart';
import 'package:github_client_app/provider/locale_provider.dart';
import 'package:provider/provider.dart';
import 'package:flutter_gen/gen_l10n/demo_localizations.dart';

class MinePage extends StatefulWidget {
  const MinePage({Key? key}) : super(key: key);

  @override
  _MinePageState createState() => _MinePageState();
}

class _MinePageState extends State<MinePage>
    with AutomaticKeepAliveClientMixin {
  @override
  Widget build(BuildContext context) {
    // print('mine build');
    return Center(
        child: Column(
      children: [
        const Text("个人中心"),
        Text(Localizations.localeOf(context).toString()),
        Text(DemoLocalizations.of(context)!.helloWorld),
        Text(DemoLocalizations.of(context)!.dataFormat(DateTime.now())),
        Consumer<LocaleProvider>(
            builder: (_, LocaleProvider localeProvider, __) {
          return Column(
            children: [
              ElevatedButton(
                  onPressed: () {
                    localeProvider.changeLanguage('en');
                  },
                  child: const Text('设置英语')),
              ElevatedButton(
                  onPressed: () {
                    localeProvider.changeLanguage('zhHans');
                  },
                  child: const Text('设置简体')),
              ElevatedButton(
                  onPressed: () {
                    localeProvider.changeLanguage('zhHant');
                  },
                  child: const Text('设置繁体')),
              ElevatedButton(
                  onPressed: () {
                    localeProvider.changeLanguage('system');
                  },
                  child: const Text('设置为系统设置')),
            ],
          );
        })
      ],
    ));
  }

  @override
  bool get wantKeepAlive => true;
}
